package com.pvdnc.tapkit.chat.ui.friend;

import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.pvdnc.nsocket.log.SLog;
import com.pvdnc.tapkit.chat.R;

import jsc.kit.adapter.SimpleAdapter;

public class SessionAdapter extends SimpleAdapter<CenterTextEntity,SessionEntity,CenterTextEntity,CenterTextEntity> {
    private static final SLog LOG=new SLog(SessionAdapter.class);

    @Override
    protected void onBindDataViewHolder(@NonNull BaseViewHolder holder, int position, SessionEntity dataBean) {
        super.onBindDataViewHolder(holder, position, dataBean);
        HeadNameEntity owner=dataBean.mOwner;
        if(owner==null){
            LOG.e("owner is null");
            return;
        }
        ImageView imgHead=holder.findViewById(R.id.imgHead);
        if(owner.mHeadImg!=null)
            imgHead.setImageBitmap(owner.mHeadImg);
        TextView lblName=holder.findViewById(R.id.lblName);
        lblName.setText(owner.mName);
        TextView lblPreview=holder.findViewById(R.id.lblPreview);
        lblPreview.setText(dataBean.mPreviewText);
    }

    @Override
    protected void onBindHeaderViewHolder(@NonNull BaseViewHolder holder, int position, CenterTextEntity headerBean) {
        super.onBindHeaderViewHolder(holder, position, headerBean);
        LinearLayout lyTip=holder.findViewById(R.id.lyTip);
        ViewGroup.LayoutParams params= lyTip.getLayoutParams();
        params.height=ViewGroup.LayoutParams.WRAP_CONTENT;
        lyTip.setLayoutParams(params);

        TextView lblTip=holder.findViewById(R.id.lblTip);
        lblTip.setText(R.string.refresh);
    }
}
